
#include "CloudiskServer.h"
#include <wfrest/HttpServer.h>

using namespace wfrest;


CloudiskServer::CloudiskServer()
:m_sigup(m_server)
,m_sigin(m_server)
,m_userInfo(m_server)
,m_fileUpLoad(m_server)
,m_fileList(m_server)
,m_fileDownload(m_server)
{};

void CloudiskServer::register_modules()
{
    // 设置静态资源的路由
    register_static_resources_module();
    register_signup_module();
    register_signin_module();
    register_userinfo_module();
    register_filelist_module();
    register_fileupload_module();
    register_filedownload_module();
}


void CloudiskServer::register_static_resources_module()
{
    m_server.GET("/user/signup", [](const HttpReq *, HttpResp * resp){
        resp->File("static/view/signup.html");
    });

    m_server.GET("/static/view/signin.html", [](const HttpReq *, HttpResp * resp){
        resp->File("static/view/signin.html");
    });

    m_server.GET("/static/view/home.html", [](const HttpReq *, HttpResp * resp){
        resp->File("static/view/home.html");
    });

    m_server.GET("/static/js/auth.js", [](const HttpReq *, HttpResp * resp){
        resp->File("static/js/auth.js");
    });

    m_server.GET("/static/img/avatar.jpeg", [](const HttpReq *, HttpResp * resp){
        resp->File("static/img/avatar.jpeg");
    });

    m_server.GET("/file/upload", [](const HttpReq *, HttpResp * resp){
        resp->File("static/view/index.html");
    });

    m_server.Static("/file/upload_files","static/view/upload_files");
}


void CloudiskServer::register_signup_module(){
    m_sigup.start();
}

void CloudiskServer::register_signin_module(){
    m_sigin.start();
}

void CloudiskServer::register_userinfo_module(){
    m_userInfo.start();
}

void CloudiskServer::register_fileupload_module(){
    m_fileUpLoad.start();
}

void CloudiskServer::register_filelist_module(){
    m_fileList.start();
}

void CloudiskServer::register_filedownload_module(){
    m_fileDownload.start();
}